﻿using Chain.BLL;
using Chain.Common.DEncrypt;
using Chain.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
public partial class PubFunction
{
    public static Dictionary<int, DataTable> _grouAuthority;
    private static CurrentParameter _parameter;
    public static bool IEbrowser = false;
    public static bool ISCheckKey = false;
    private static Random r = new Random();
    private static object SynGroupObject = new object();
    private static object SynObject = new object();

    public static void AddShopPoint(int UserID, int ShopID, int Point, string Remark)
    {
        if ((Point != 0) && ((ShopID > 1) && curParameter.isPointSame))
        {
            Chain.BLL.SysShop bllSysShop = new Chain.BLL.SysShop();
            Chain.Model.SysShop mdSysShop = new Chain.Model.SysShop();
            mdSysShop = bllSysShop.GetModel(ShopID);
            mdSysShop.PointCount += Point;
            bllSysShop.Update(mdSysShop);
            Chain.BLL.SysShopPointLog bllSysShopPointLog = new Chain.BLL.SysShopPointLog();
            Chain.Model.SysShopPointLog mdSysShopPointLog = new Chain.Model.SysShopPointLog();
            mdSysShopPointLog.Count = Point;
            mdSysShopPointLog.Remark = Remark;
            mdSysShopPointLog.CreateTime = DateTime.Now;
            mdSysShopPointLog.OutShopID = ShopID;
            mdSysShopPointLog.ShopID = ShopID;
            mdSysShopPointLog.ShopPointAccount = "JF" + DateTime.Now.ToString("yyMMddHHmmssffff");
            mdSysShopPointLog.ShopPointType = 3;
            mdSysShopPointLog.UserID = UserID;
            bllSysShopPointLog.Add(mdSysShopPointLog);
        }
    }

    public static void AgainPrint(ref Label lblPrintTitle, ref Label lblPrintFoot, int _UserShopID)
    {
        if (curParameter.bolAccordPrint)
        {
            lblPrintTitle.Text = curParameter.strPrintTitle;
            lblPrintFoot.Text = curParameter.strPrintFootNote;
        }
        else
        {
            Chain.Model.SysShop modelShop = new Chain.BLL.SysShop().GetModel(_UserShopID);
            lblPrintTitle.Text = modelShop.ShopPrintTitle;
            lblPrintFoot.Text = modelShop.ShopPrintFoot;
        }
    }

    public static void BindAddCustomFields(HtmlContainerControl container, string type)
    {
        DataRow[] drs = new Chain.BLL.MemCustomField().CustomGetList("CustomType=" + ((type == "Mem") ? "1" : "2"));
        string strPre = (type == "Mem") ? "Mem_Custom_" : "Goods_Custom_";
        int index = 0;
        StringBuilder sbHtml = new StringBuilder();
        if (drs.Length <= 0)
        {
            sbHtml.Append("<tr>");
            sbHtml.Append("<td style='text-align:left;padding:2px;' colspan='4'>您可以根据需要在‘系统管理’---> ‘自定义属性设置’ 增加自定义属性。</td>");
            sbHtml.Append("</tr>");
        }
        StringBuilder sbControl = new StringBuilder("<script>");
        foreach (DataRow dr in drs)
        {
            if ((index % 2) == 0)
            {
                sbHtml.Append("<tr>\n");
            }
            sbHtml.Append("<td class='tableStyle_left'>");
            if (!Convert.ToBoolean(dr["CustomFieldIsNull"].ToString()))
            {
                sbHtml.Append("<font color=\"#ff4800\"><strong>*</strong></font>");
            }
            sbHtml.Append(string.Concat(new object[] { "<span id='", strPre, "T_", dr["CustomField"], "'>", dr["CustomFieldName"], "</span>：</td>\n" }));
            sbHtml.Append("<td class='tableStyle_right' style='width: 270px'>");
            if (dr["CustomFieldType"].ToString() == "text")
            {
                sbHtml.Append(string.Concat(new object[] { "<input type='text' id='", strPre, dr["CustomField"], "' name='", strPre, dr["CustomField"], "' isNull='", dr["CustomFieldIsNull"], "' class='border_radius'/>" }));
            }
            else if (dr["CustomFieldType"].ToString() == "select")
            {
                string[] strInfo = dr["CustomFieldInfo"].ToString().Split("|".ToCharArray());
                sbHtml.Append(string.Concat(new object[] { "<select id='", strPre, dr["CustomField"], "' name='", strPre, dr["CustomField"], "' class='selectWidth' isNull='", dr["CustomFieldIsNull"], "' isSelect='true' >" }));
                sbHtml.Append("<option value='无'>===== 请选择 =====</option>");
                for (int i = 0; i < strInfo.Length; i++)
                {
                    sbHtml.Append("<option value='" + strInfo[i] + "'>" + strInfo[i] + "</option>");
                }
                sbHtml.Append("</select>");
            }
            else if (dr["CustomFieldType"].ToString() == "date")
            {
                sbHtml.Append(string.Concat(new object[] { "<input type='text' id='", strPre, dr["CustomField"], "' class='Wdate border_radius' name='", strPre, dr["CustomField"], "' isNull='", dr["CustomFieldIsNull"], "' onfocus=\"WdatePicker({ skin: 'ext', isShowClear: false, readOnly: true });\"/>" }));
            }
            sbHtml.Append("</td>\n");
            if ((index % 2) == 1)
            {
                sbHtml.Append("</tr>\n");
            }
            index++;
        }
        if ((drs.Length != 0) && ((drs.Length % 2) == 1))
        {
            sbHtml.Append("<td class='tableStyle_left'></td><td class='tableStyle_right' style='width: 270px'></td></tr>\n");
        }
        sbControl.Append("</script>");
        container.InnerHtml = sbHtml.ToString() + sbControl.ToString();
    }

    public static void BindAuthoritySelelct(int ShopID, int GroupID, HtmlSelect select, bool hasEmpty)
    {
        object name1 = string.Format(" (IsPublic = 'true' or CreateUserID in (select UserID from sysUser where UserShopID={0})) ", ShopID);
        string strSql = string.Concat(new object[] { name1, " and (ParentIDStr like '%/", GroupID, "/%' or GroupID = ", GroupID, ")" });
        DataTable dtGroup = new Chain.BLL.SysGroup().GetList(strSql).Tables[0];
        if (hasEmpty)
        {
            select.Items.Add(new ListItem("全部", ""));
        }
        foreach (DataRow dr in dtGroup.Rows)
        {
            select.Items.Add(new ListItem(dr["GroupName"].ToString(), dr["GroupID"].ToString()));
        }
    }

    public static void BindCouponSelect(HtmlSelect select, bool bolAddEmpty)
    {
        select.Items.Clear();
        if (bolAddEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        Chain.BLL.Coupon bllCoupon = new Chain.BLL.Coupon();
        DataTable dtCoupon = bllCoupon.GetList("").Tables[0];
        foreach (DataRow dr in dtCoupon.Rows)
        {
            if (dr["CouponEffective"].ToString() == "0")
            {
                select.Items.Add(new ListItem(dr["CouponTitle"].ToString(), dr["ID"].ToString()));
            }
            else
            {
                if ((dr["CouponStart"].ToString() != "") && (dr["CouponEnd"].ToString() != ""))
                {
                    DateTime dttStart = DateTime.Parse(dr["CouponStart"].ToString());
                    DateTime dttEnd = DateTime.Parse(dr["CouponEnd"].ToString());
                    if ((dttStart < DateTime.Now) && (dttEnd > DateTime.Now))
                    {
                        select.Items.Add(new ListItem(dr["CouponTitle"].ToString(), dr["ID"].ToString()));
                    }
                    continue;
                }
                select.Items.Add(new ListItem(dr["CouponTitle"].ToString(), dr["ID"].ToString()));
            }
        }
    }

    public static void BindCustomField(int ShopID, HtmlSelect select, bool hasEmpty, int intCustomType)
    {
        if (hasEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        Chain.BLL.MemCustomField bllCustom = new Chain.BLL.MemCustomField();
        DataTable dtCustom = new DataTable();
        if (intCustomType == 1)
        {
            dtCustom = bllCustom.GetList(" CustomType=1 ").Tables[0];
        }
        else
        {
            dtCustom = bllCustom.GetList(" CustomType=2 ").Tables[0];
        }
        foreach (DataRow dr in dtCustom.Rows)
        {
            ListItem item = new ListItem(dr["CustomFieldName"].ToString(), dr["CustomField"].ToString());
            item.Attributes.Add("CustomFieldType", dr["CustomFieldType"].ToString());
            item.Attributes.Add("CustomFieldInfo", dr["CustomFieldInfo"].ToString());
            select.Items.Add(item);
        }
    }

    public static void BindCustomFieldSelect(int ShopID, HtmlSelect select, bool hasEmpty, int intCustomType)
    {
        if (hasEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        Chain.BLL.MemCustomField bllCustom = new Chain.BLL.MemCustomField();
        DataTable dtCustom = new DataTable();
        if (intCustomType == 1)
        {
            dtCustom = bllCustom.GetList(" CustomType=1 and CustomFieldShopID=" + ShopID).Tables[0];
        }
        else
        {
            dtCustom = bllCustom.GetList(" CustomType=2 and CustomFieldShopID=" + ShopID).Tables[0];
        }
        foreach (DataRow dr in dtCustom.Rows)
        {
            select.Items.Add(new ListItem(dr["CustomFieldName"].ToString(), dr["CustomField"].ToString()));
        }
    }

    public static void BindEditCustomFields(HtmlContainerControl container, string type, DataRow row)
    {
        DataRow[] drs = new Chain.BLL.MemCustomField().CustomGetList("CustomType=" + ((type == "Mem") ? "1" : "2"));
        string strPre = (type == "Mem") ? "Mem_Custom_" : "Goods_Custom_";
        int index = 0;
        StringBuilder sbHtml = new StringBuilder();
        if (drs.Length <= 0)
        {
            sbHtml.Append("<tr>");
            sbHtml.Append("<td style='text-align:left;padding:2px;' colspan='4'>您可以根据需要在‘系统管理’---> ‘自定义属性设置’ 增加自定义属性。</td>");
            sbHtml.Append("</tr>");
        }
        StringBuilder sbControl = new StringBuilder("<script>");
        foreach (DataRow dr in drs)
        {
            if ((index % 2) == 0)
            {
                sbHtml.Append("<tr>\n");
            }
            sbHtml.Append("<td class='tableStyle_left'>");
            if (!Convert.ToBoolean(dr["CustomFieldIsNull"].ToString()))
            {
                sbHtml.Append("<font color=\"#ff4800\"><strong>*</strong></font>");
            }
            sbHtml.Append(string.Concat(new object[] { "<span id='", strPre, "T_", dr["CustomField"], "'>", dr["CustomFieldName"], "</span>：</td>\n" }));
            sbHtml.Append("<td class='tableStyle_right' style='width: 270px'>");
            if (dr["CustomFieldType"].ToString() == "text")
            {
                sbHtml.Append(string.Concat(new object[] { "<input type='text' id='", strPre, dr["CustomField"], "' name='", strPre, dr["CustomField"], "' isNull='", dr["CustomFieldIsNull"], "' class='border_radius'  value='", row[dr["CustomField"].ToString()].ToString(), "'/>" }));
            }
            else if (dr["CustomFieldType"].ToString() == "select")
            {
                string[] strInfo = dr["CustomFieldInfo"].ToString().Split("|".ToCharArray());
                sbHtml.Append(string.Concat(new object[] { "<select id='", strPre, dr["CustomField"], "' name='", strPre, dr["CustomField"], "' class='selectWidth' isNull='", dr["CustomFieldIsNull"], "'isSelect='true' >" }));
                sbHtml.Append("<option value='无'>===== 请选择 =====</option>");
                for (int i = 0; i < strInfo.Length; i++)
                {
                    if (strInfo[i] == row[dr["CustomField"].ToString()].ToString())
                    {
                        sbHtml.Append("<option value='" + strInfo[i] + "' selected>" + strInfo[i] + "</option>");
                    }
                    else
                    {
                        sbHtml.Append("<option value='" + strInfo[i] + "'>" + strInfo[i] + "</option>");
                    }
                }
                sbHtml.Append("</select>");
            }
            else if (dr["CustomFieldType"].ToString() == "date")
            {
                sbHtml.Append(string.Concat(new object[] { "<input type='text' id='", strPre, dr["CustomField"], "' class='Wdate border_radius' name='", strPre, dr["CustomField"], "' isNull='", dr["CustomFieldIsNull"], "' value='", row[dr["CustomField"].ToString()].ToString(), "' onfocus=\"WdatePicker({ skin: 'ext', isShowClear: false, readOnly: true });\"/>" }));
            }
            sbHtml.Append("</td>\n");
            if ((index % 2) == 1)
            {
                sbHtml.Append("</tr>\n");
            }
            index++;
        }
        if ((drs.Length != 0) && ((drs.Length % 2) == 1))
        {
            sbHtml.Append("<td class='tableStyle_left'></td><td class='tableStyle_right' style='width: 270px'></td></tr>\n");
        }
        sbControl.Append("</script>");
        container.InnerHtml = sbHtml.ToString() + sbControl.ToString();
    }

    public static string BindFatherHtml(int fatherID, string strhtml)
    {
        Chain.Model.SysModule mdSysModule = new Chain.BLL.SysModule().GetModel(fatherID);
        if (mdSysModule.ModuleParentID > 0)
        {
            strhtml = strhtml + BindFatherHtml(mdSysModule.ModuleParentID, strhtml);
        }
        if (!string.IsNullOrEmpty(mdSysModule.ModuleLink))
        {
            strhtml = strhtml + string.Format("&nbsp;&nbsp;<a href='{0}'>{1}</a>&nbsp;&nbsp;>", "/" + mdSysModule.ModuleLink, mdSysModule.ModuleCaption);
            return strhtml;
        }
        strhtml = strhtml + string.Format("&nbsp;&nbsp;{0}&nbsp;&nbsp;>", mdSysModule.ModuleCaption);
        return strhtml;
    }

    public static void BindGiftClass(HtmlSelect select)
    {
        select.Items.Clear();
        select.Items.Add(new ListItem("===== 请选择 =====", ""));
        DataTable dtGiftClass = new Chain.BLL.GiftClass().GetList("").Tables[0];
        int index = 1;
        CreateGiftClassItem(ref select, ref index, dtGiftClass, "0");
    }

    public static void BindGoodsClass(HtmlSelect select, int ShopID)
    {
        select.Items.Clear();
        select.Items.Add(new ListItem("===== 请选择 =====", ""));
        DataTable dtGoodsClass = new Chain.BLL.GoodsClass().GetListByShopID(ShopID).Tables[0];
        int index = 1;
        CreateGoodsClassItem(ref select, ref index, dtGoodsClass, "0");
    }

    public static void BindMemInfoCustomFields(HtmlContainerControl container, string type, string pre)
    {
        DataRow[] drs = new Chain.BLL.MemCustomField().CustomGetList("CustomType=" + ((type == "Mem") ? "1" : "2"));
        int index = 0;
        StringBuilder sbHtml = new StringBuilder();
        foreach (DataRow dr in drs)
        {
            if ((index % 2) == 0)
            {
                sbHtml.Append("<tr>\n");
            }
            sbHtml.Append(string.Concat(new object[] { "<td class='tableStyle_left' id='", pre, "T_", dr["CustomField"], "'>", dr["CustomFieldName"], "：</td>\n" }));
            sbHtml.Append(string.Concat(new object[] { "<td class='tableStyle_right'><span id='", pre, dr["CustomField"], "'></span></td>\n" }));
            if ((index % 2) == 1)
            {
                sbHtml.Append("</tr>\n");
            }
            index++;
        }
        if ((drs.Length != 0) && (sbHtml.ToString().Substring(sbHtml.Length - 5, 5) != "</tr>"))
        {
            sbHtml.Append("<td class='tableStyle_left'></td><td  class='tableStyle_right'></td></tr>\n");
        }
        container.InnerHtml = sbHtml.ToString();
    }

    public static void BindMemLevelSelect(HtmlSelect select, bool bolAddEmpty)
    {
        select.Items.Clear();
        if (bolAddEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        DataTable dtblLevel = new Chain.BLL.MemLevel().GetList("").Tables[0];
        foreach (DataRow drowLevel in dtblLevel.Rows)
        {
            double.Parse(drowLevel["LevelPointPercent"].ToString());
            double.Parse(drowLevel["LevelDiscountPercent"].ToString());
            select.Items.Add(new ListItem(drowLevel["LevelName"].ToString(), drowLevel["LevelID"].ToString()));
        }
    }

    public static void BindProvinceSelect(HtmlSelect select)
    {
        Chain.BLL.SysArea bllArea = new Chain.BLL.SysArea();
        DataTable dtArea = bllArea.GetList("PID=0").Tables[0];
        select.Items.Add(new ListItem("=== 请选择 ===", ""));
        foreach (DataRow dr in dtArea.Rows)
        {
            select.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
        }
    }

    public static void BindShopArea(HtmlSelect select, bool hasEmpty)
    {
        DataTable dtShop = new Chain.BLL.SysArea().GetList("").Tables[0];
        if (hasEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        foreach (DataRow dr in dtShop.Rows)
        {
            select.Items.Add(new ListItem(dr["AreaName"].ToString(), dr["AreaID"].ToString()));
        }
    }

    public static void BindShopSelect(int intShopID, HtmlSelect select, bool bolAddEmpty)
    {
        string strShopAuth = "ShopID>0";
        DataTable dtShopAuth = GetShopAuthority(intShopID);
        if (dtShopAuth.Rows.Count > 0)
        {
            strShopAuth = strShopAuth + " and ShopID in (" + dtShopAuth.Rows[0]["ShopAuthorityData"].ToString() + ") and ShopState='false' ";
        }
        Chain.BLL.SysShop bllShop = new Chain.BLL.SysShop();
        DataTable dtShop = bllShop.GetList(strShopAuth).Tables[0];
        select.Items.Clear();
        if (bolAddEmpty)
        {
            select.Items.Add(new ListItem("全部", ""));
        }
        foreach (DataRow dr in dtShop.Rows)
        {
            select.Items.Add(new ListItem(dr["ShopName"].ToString(), dr["ShopID"].ToString()));
        }
    }

    public static void BindShopSelect(int intShopID, HtmlSelect select, int intTragetShopID, bool boolIsDisabled)
    {
        string strShopAuth = "ShopID>0";
        DataTable dtShopAuth = GetShopAuthority(intShopID);
        if (dtShopAuth.Rows.Count > 0)
        {
            strShopAuth = strShopAuth + " and ShopID in (" + dtShopAuth.Rows[0]["ShopAuthorityData"].ToString() + ")";
        }
        Chain.BLL.SysShop bllShop = new Chain.BLL.SysShop();
        DataTable dtShop = bllShop.GetList(strShopAuth).Tables[0];
        select.Items.Clear();
        if (intTragetShopID == 0)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        foreach (DataRow dr in dtShop.Rows)
        {
            ListItem lt = new ListItem(dr["ShopName"].ToString(), dr["ShopID"].ToString());
            if (Convert.ToInt32(dr["ShopID"]) == intTragetShopID)
            {
                lt.Selected = true;
            }
            select.Items.Add(lt);
        }
        select.Disabled = boolIsDisabled;
    }

    public static void BindSmsTemplate(HtmlSelect select)
    {
        select.Items.Clear();
        select.Items.Add(new ListItem("===== 请选择 =====", ""));
        DataTable dtSmsTemplate = new Chain.BLL.SmsTemplate().GetList("TemplateID>9").Tables[0];
        foreach (DataRow drSmsTemplate in dtSmsTemplate.Rows)
        {
            select.Items.Add(new ListItem(drSmsTemplate["TemplateName"].ToString(), drSmsTemplate["TemplateContent"].ToString()));
        }
    }
    public static void BindSmsTemplate_new(HtmlSelect select)
    {
        select.Items.Clear();
        select.Items.Add(new ListItem("===== 请选择 =====", ""));
        DataTable dtSmsTemplate = new Chain.BLL.SmsTemplate().GetList("TemplateID>9").Tables[0];
        foreach (DataRow drSmsTemplate in dtSmsTemplate.Rows)
        {

            select.Items.Add(new ListItem(drSmsTemplate["TemplateName"].ToString(), Regex.Replace(drSmsTemplate["TemplateContent"].ToString(), @"\{[^\}]+\}", "{填写内容}")));
        }
    }
    public static void BindStaff(int intShopID, HtmlSelect select, bool bolAddEmpty)
    {
        string strShopAuth = " SysShop.ShopID = StaffClass.ClassShopID and StaffClass.ClassID=Staff.StaffClassID ";
        strShopAuth = strShopAuth + " and ClassShopID=" + intShopID;
        Chain.BLL.Staff bllStaff = new Chain.BLL.Staff();
        DataTable dtStaff = bllStaff.GetList(strShopAuth).Tables[0];
        DataView dvStaff = dtStaff.DefaultView;
        dvStaff.Sort = " StaffClassID ASC";
        dtStaff = dvStaff.ToTable();
        select.Items.Clear();
        if (bolAddEmpty)
        {
            ListItem item = new ListItem("=== 请选择 ===", "");
            item.Attributes.Add("ClassPercent", "0");
            select.Items.Add(item);
        }
        foreach (DataRow dr in dtStaff.Rows)
        {
            Chain.BLL.StaffClass bllClass = new Chain.BLL.StaffClass();
            Chain.Model.StaffClass modelClass = new Chain.Model.StaffClass();
            modelClass = bllClass.GetModel(int.Parse(dr["StaffClassID"].ToString()));
            ListItem item = new ListItem(modelClass.ClassName + "--" + dr["StaffName"].ToString(), dr["StaffID"].ToString());
            item.Attributes.Add("ClassPercent", modelClass.ClassPercent.ToString());
            select.Items.Add(item);
        }
    }

    public static void BindStaffClass(int intShopID, HtmlSelect select, bool bolAddEmpty)
    {
        string strShopAuth = " SysShop.ShopID = StaffClass.ClassShopID ";
        DataTable dtShopAuth = GetShopAuthority(intShopID);
        if (dtShopAuth.Rows.Count > 0)
        {
            strShopAuth = strShopAuth + " and ClassShopID in (" + dtShopAuth.Rows[0]["ShopAuthorityData"].ToString() + ")";
        }
        Chain.BLL.StaffClass bllClass = new Chain.BLL.StaffClass();
        DataTable dtClass = bllClass.GetList(strShopAuth).Tables[0];
        DataView dvClass = dtClass.DefaultView;
        dvClass.Sort = " ClassShopID ASC ";
        dtClass = dvClass.ToTable();
        select.Items.Clear();
        if (bolAddEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        foreach (DataRow dr in dtClass.Rows)
        {
            Chain.BLL.SysShop bllShop = new Chain.BLL.SysShop();
            Chain.Model.SysShop modelShop = new Chain.Model.SysShop();
            modelShop = bllShop.GetModel(int.Parse(dr["ClassShopID"].ToString()));
            select.Items.Add(new ListItem(modelShop.ShopName + "--" + dr["ClassName"].ToString(), dr["ClassID"].ToString()));
        }
    }

    public static void BindSysArea(HtmlSelect select, int pid)
    {
        Chain.BLL.SysArea bllArea = new Chain.BLL.SysArea();
        DataTable dtArea = bllArea.GetList(" PID=" + pid).Tables[0];
        select.Items.Add(new ListItem("=== 请选择 ===", ""));
        foreach (DataRow dr in dtArea.Rows)
        {
            select.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
        }
    }

    public static void BindUserSelect(int intShopID, HtmlSelect select, bool bolAddEmpty, bool bolAllUser)
    {
        DataTable dtUser;
        if (bolAddEmpty)
        {
            select.Items.Add(new ListItem("===== 请选择 =====", ""));
        }
        Chain.BLL.SysUser bllUser = new Chain.BLL.SysUser();
        if (bolAllUser)
        {
            dtUser = bllUser.GetList("").Tables[0];
        }
        else
        {
            dtUser = bllUser.GetList(GetShopAuthority(intShopID, "UserShopID", "1=1")).Tables[0];
        }
        foreach (DataRow dr in dtUser.Rows)
        {
            select.Items.Add(new ListItem(dr["UserName"].ToString(), dr["UserID"].ToString()));
        }
    }

    public static Chain.Model.SysUser CheckUserLogin(string UserAccount, string Pwd)
    {
        Chain.BLL.SysUser bll = new Chain.BLL.SysUser();
        return bll.CheckUserLogin(UserAccount, DESEncrypt.Encrypt(Pwd));
    }

    public static void CreateGiftClassItem(ref HtmlSelect select, ref int index, DataTable dt, string pid)
    {
        if (pid != "0")
        {
            index++;
        }
        foreach (DataRow dr in dt.Select(" GiftParentID=" + pid))
        {
            string blank = "";
            for (int i = 1; i < index; i++)
            {
                blank = blank + "----";
            }
            ListItem item = new ListItem(blank + dr["GiftClassName"].ToString(), dr["GiftClassID"].ToString());
            if (dt.Select("GiftParentID=" + dr["GiftClassID"].ToString()).Length > 0)
            {
                item.Attributes.Add("parent", "true");
            }
            select.Items.Add(item);
            CreateGiftClassItem(ref select, ref index, dt, dr["GiftClassID"].ToString());
            index--;
        }
    }

    public static void CreateGoodsClassItem(ref HtmlSelect select, ref int index, DataTable dt, string pid)
    {
        if (pid != "0")
        {
            index++;
        }
        foreach (DataRow dr in dt.Select(" ParentID=" + pid))
        {
            string blank = "";
            for (int i = 1; i < index; i++)
            {
                blank = blank + "----";
            }
            ListItem item = new ListItem(blank + dr["ClassName"].ToString(), dr["ClassID"].ToString());
            if (dt.Select("ParentID=" + dr["ClassID"].ToString()).Length > 0)
            {
                item.Attributes.Add("parent", "true");
            }
            select.Items.Add(item);
            CreateGoodsClassItem(ref select, ref index, dt, dr["ClassID"].ToString());
            index--;
        }
    }

    public static string CreateRandomNumber(int length)
    {
        string strLetters = "1234567890";
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < length; i++)
        {
            s.Append(strLetters.Substring(r.Next(0, strLetters.Length - 1), 1));
        }
        return (DateTime.Now.ToString("HHmmssffff") + s.ToString());
    }

    public static void DeleteUpLoad(string strPath)
    {
        try
        {
            if (Directory.Exists(strPath))
            {
                foreach (string filepath in Directory.GetFiles(strPath))
                {
                    FileInfo fi = new FileInfo(filepath);
                    if (fi.CreationTime <= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
                    {
                        fi.Delete();
                    }
                }
            }
        }
        catch
        {
        }
    }

    public static DataTable DoubleAuotesEscape(DataTable dt)
    {
        if ((dt != null) && (dt.Rows.Count > 0))
        {
            for (int rowItem = 0; rowItem < dt.Rows.Count; rowItem++)
            {
                for (int cellItem = 0; cellItem < dt.Columns.Count; cellItem++)
                {
                    if (dt.Rows[rowItem][cellItem] != null)
                    {
                        dt.Rows[rowItem][cellItem] = dt.Rows[rowItem][cellItem].ToString().Replace("\"", "\\\"").Replace("\r\n", "").Replace("\n", "");
                    }
                }
            }
        }
        return dt;
    }

    public static void Get_MenuCaption(int MenuID, ref Label lblTitle, ref Image imgTitle)
    {
        try
        {
            Chain.Model.SysModule module = new Chain.BLL.SysModule().GetModel(MenuID);
            lblTitle.Text = module.ModuleCaption;
            imgTitle.ImageUrl = "../" + module.ModuleIcoPath;
        }
        catch
        {
        }
    }

    public static void Get_PrintTitle(ref Label litPrintTitle, ref Label litPrintFoot, int ShopID)
    {
        if (curParameter.bolAccordPrint)
        {
            litPrintTitle.Text = curParameter.strPrintTitle;
            litPrintFoot.Text = curParameter.strPrintFootNote;
        }
        else
        {
            Chain.Model.SysShop modelShop = new Chain.BLL.SysShop().GetModel(ShopID);
            litPrintTitle.Text = modelShop.ShopPrintTitle;
            litPrintFoot.Text = modelShop.ShopPrintFoot;
        }
    }

    public static string GetClassID(int id)
    {
        string strClass = "";
        DataRow[] drs = new Chain.BLL.GoodsClass().GetList("").Tables[0].Select(" ParentID=" + id);
        strClass = strClass + id;
        if (drs.Length > 0)
        {
            foreach (DataRow dr in drs)
            {
                strClass = strClass + "," + int.Parse(dr["ClassID"].ToString());
            }
        }
        return strClass;
    }

    public static bool GetControlVisit(DataTable db, int ActionID, int PageID)
    {
        DataRow[] dr = db.Select(string.Concat(new object[] { "ActionID=", ActionID, " and ModuleID=", PageID }));
        return ((dr.Length > 0) && Convert.ToBoolean(dr[0]["ActionValue"]));
    }

    public static bool GetControlVisit(DataTable db, string strControl, int PageID)
    {
        DataRow[] dr = db.Select(string.Concat(new object[] { "ActionControl='", strControl, "' and ModuleID=", PageID }));
        return ((dr.Length > 0) && Convert.ToBoolean(dr[0]["ActionValue"]));
    }

    public static string GetDataTimeString()
    {
        return DateTime.Now.ToString("hhmmssffff");
    }

    public static string GetGoodsAuthority(int intShopID, string strTableShopName, string SqlWhere)
    {
        return "";
    }

    public static DataTable GetGroupAuthority(int GroupID)
    {
        if (_grouAuthority == null)
        {
            _grouAuthority = new Dictionary<int, DataTable>();
        }
        if (!_grouAuthority.ContainsKey(GroupID))
        {
            lock (SynObject)
            {
                if (!_grouAuthority.ContainsKey(GroupID))
                {
                    _grouAuthority.Add(GroupID, GetUserAuthority(GroupID));
                }
            }
        }
        return _grouAuthority[GroupID];
    }

    public static string GetMemSex(bool bolMemSex)
    {
        if (bolMemSex)
        {
            return "男";
        }
        return "女";
    }

    public static string GetMemState(int intMemState)
    {
        if (intMemState == 0)
        {
            return "正常";
        }
        if (intMemState == 1)
        {
            return "锁定";
        }
        return "挂失";
    }

    public static bool GetPageVisit(DataTable db, int PageID)
    {
        DataRow[] dr = db.Select("ActionControl='page' and ModuleID=" + PageID);
        return ((dr.Length > 0) && Convert.ToBoolean(dr[0]["ActionValue"]));
    }

    public static string GetPointNum(string yemian)
    {
        string[] Number = curParameter.PointNumStr.Split(new char[] { '$' });
        switch (yemian)
        {
            case "HYCZ":
                return Number[0];

            case "JFBD":
                return Number[1];

            case "JFDH":
                return Number[2];

            case "SPRK":
                return Number[3];

            case "SPXF":
                return Number[4];

            case "JCXF":
                return Number[5];

            case "KSXF":
                return Number[6];

            case "HYCC":
                return Number[7];

            case "HYCS":
                return Number[8];

            case "XFJL":
                return Number[9];

            case "HYCZBB":
                return Number[10];

            case "JFBDBB":
                return Number[11];

            case "JFDHBB":
                return Number[12];

            case "CKRKML":
                return Number[13];

            case "ZHTX":
                return Number[14];
        }
        return "";
    }

    public static string GetProperties<T>(T t)
    {
        string tStr = string.Empty;
        if (t != null)
        {
            PropertyInfo[] properties = t.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            if (properties.Length <= 0)
            {
                return tStr;
            }
            foreach (PropertyInfo item in properties)
            {
                string name = item.Name;
                object value = item.GetValue(t, null);
                if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
                {
                    if (string.IsNullOrEmpty(tStr))
                    {
                        tStr = tStr + string.Format("{0}:'{1}'", name, value);
                    }
                    else
                    {
                        tStr = tStr + string.Format(",{0}:'{1}'", name, value);
                    }
                }
                else
                {
                    GetProperties<object>(value);
                }
            }
        }
        return tStr;
    }

    public static DataTable GetShopAuthority(int ShopID)
    {
        Chain.BLL.SysShopAuthority shopAuthority = new Chain.BLL.SysShopAuthority();
        return shopAuthority.GetShopAuthority(ShopID).Tables[0];
    }

    public static string GetShopAuthority(int intShopID, string strTableShopName, string SqlWhere)
    {
        string strAuthorityData = "";
        Chain.BLL.SysShopAuthority bllShopAuthority = new Chain.BLL.SysShopAuthority();
        DataTable dtShopAuthority = bllShopAuthority.GetShopAuthority(intShopID).Tables[0];
        if (curParameter.dataAuthority == 0)
        {
            foreach (DataRow drShopAuthority in dtShopAuthority.Rows)
            {
                if (drShopAuthority["ShopAuthorityShopID"].ToString() == intShopID.ToString())
                {
                    strAuthorityData = drShopAuthority["ShopAuthorityData"].ToString();
                }
                if (SqlWhere.Length > 0)
                {
                    string name3 = SqlWhere;
                    SqlWhere = name3 + " and " + strTableShopName + " in (" + strAuthorityData + ")";
                }
            }
            return SqlWhere;
        }
        if (intShopID > 1)
        {
            object name4 = SqlWhere;
            SqlWhere = string.Concat(new object[] { name4, " and ", strTableShopName, " =", intShopID });
            return SqlWhere;
        }
        SqlWhere = SqlWhere + " and " + strTableShopName + " >0 ";
        return SqlWhere;
    }

    public static decimal GetSingleStaffMoney()
    {
        return 0M;
    }

    public static int GetSmsAmount(string smsContent)
    {
        double d = ((double) smsContent.Length) / 65.0;
        return int.Parse(Math.Ceiling(d).ToString());
    }

    public static DataTable GetUserAuthority(int GroupID)
    {
        Chain.BLL.SysGroup bll = new Chain.BLL.SysGroup();
        return bll.GetGroupAuthority(GroupID).Tables[0];
    }

    public static int GoodsCodeToGoodsID(string goodsCode)
    {
        DataTable dt = new Chain.BLL.Goods().GetList(" GoodsCode='" + goodsCode + "'").Tables[0];
        return int.Parse(dt.Rows[0][0].ToString());
    }

    public static string GroupIDToName(int group)
    {
        Chain.Model.SysGroup modelGroup = new Chain.BLL.SysGroup().GetModel(group);
        if (modelGroup != null)
        {
            return modelGroup.GroupName;
        }
        return "";
    }

    public static bool IsCanBuyCard(string StartCardNumber, string EndCardNumber)
    {
        bool result = true;
        long intStart = Convert.ToInt64(StartCardNumber);
        long intEnd = Convert.ToInt64(EndCardNumber);
        Chain.BLL.SysShopBuyCard bllSysShopBuyCard = new Chain.BLL.SysShopBuyCard();
        string strWhere = " LEN(StartCardNumber) = '{0}' AND ((CONVERT(BIGINT,StartCardNumber) < ='{1}' AND CONVERT(BIGINT,EndCardNumber) >='{2}')\r\n                           OR (CONVERT(BIGINT,StartCardNumber) < ='{3}' AND CONVERT(BIGINT,EndCardNumber) >='{4}'))";
        strWhere = string.Format(strWhere, new object[] { StartCardNumber.Length, intStart, intStart, intEnd, intEnd });
        DataTable dtSysShopBuyCard = bllSysShopBuyCard.GetList(strWhere).Tables[0];
        if (dtSysShopBuyCard.Rows.Count > 0)
        {
            result = false;
        }
        return result;
    }

    public static bool IsCanRegisterCard(int ShopID, string MemCard, string MemCardNumber)
    {
        try
        {
            long intCard = Convert.ToInt64(MemCard);
            long lenCard = MemCard.Length;
            Chain.BLL.SysShopBuyCard bllSysShopBuyCard = new Chain.BLL.SysShopBuyCard();
            string strCondition = " CONVERT(BIGINT,StartCardNumber) < = '{0}' AND CONVERT(BIGINT,EndCardNumber) > = '{1}' AND\r\n                           LEN(StartCardNumber) < = '{2}' AND LEN(EndCardNumber) > = '{3}' AND BuyCardShopid = '{4}'";
            string StrWhere = string.Format(strCondition, new object[] { intCard, intCard, lenCard, lenCard, ShopID });
            DataTable dt = bllSysShopBuyCard.GetList(StrWhere).Tables[0];
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            if (!string.IsNullOrEmpty(MemCardNumber))
            {
                long intCardNumber = Convert.ToInt64(MemCardNumber);
                long lenCardNumber = MemCardNumber.Length;
                StrWhere = string.Format(strCondition, new object[] { intCardNumber, intCardNumber, lenCardNumber, lenCardNumber, ShopID });
                dt = bllSysShopBuyCard.GetList(StrWhere).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return true;
                }
            }
        }
        catch
        {
        }
        return false;
    }

    public static bool IsCanSendSms(int ShopID, int MemMobileCount)
    {
        if (curParameter.UsingUnion)
        {
            Chain.Model.SysShop mdSysShop = new Chain.BLL.SysShop().GetModel(ShopID);
            if (((ShopID > 1) && curParameter.IsSmsSame) && ((mdSysShop.SmsCount < MemMobileCount) && (mdSysShop.SmsType == 1)))
            {
                return false;
            }
        }
        return true;
    }

    public static bool IsShopPoint(int ShopID, ref int Point)
    {
        if ((curParameter.UsingUnion && curParameter.bolShopPointManage) && ((ShopID > 1) && (Point != 0)))
        {
            Chain.BLL.SysShop bllSysShop = new Chain.BLL.SysShop();
            Chain.Model.SysShop mdSysShop = new Chain.Model.SysShop();
            mdSysShop = bllSysShop.GetModel(ShopID);
            if (curParameter.isPointSame && (mdSysShop.PointCount < Point))
            {
                if (mdSysShop.PointType == 1)
                {
                    return false;
                }
                if (mdSysShop.PointType == 2)
                {
                    Point = 0;
                }
            }
        }
        return true;
    }

    public static string LevelIDToName(int levelID)
    {
        return new Chain.BLL.MemLevel().GetModel(levelID).LevelName;
    }

    public CurrentParameter LoadSysParameter()
    {
        CurrentParameter parameter = new CurrentParameter();
        Chain.Model.SysParameter modelParameter = new Chain.Model.SysParameter();
        Chain.BLL.SysParameter bllParameter = new Chain.BLL.SysParameter();
        modelParameter = bllParameter.GetModel(1);
        parameter.bolPwd = modelParameter.Pwd;
        parameter.RegNullPwd = modelParameter.RegNullPwd;
        parameter.bolMoneyAndPoint = modelParameter.MoneyAndPoint;
        parameter.bolAutoLevel = modelParameter.AutoLevel;
        parameter.bolDegradeLevel = modelParameter.DegradeLevel;
        parameter.bolPastTime = modelParameter.PastTime;
        parameter.intRecommendPoint = modelParameter.RecommendPoint;
        parameter.DrawMoneyPercent = modelParameter.DrawMoneyPercent;
        parameter.intPointPeriod = modelParameter.PointPeriod;
        parameter.strExpensePrefix = modelParameter.ExpensePrefix;
        parameter.strGoodsExpensePrefix = modelParameter.GoodsExpensePrefix;
        parameter.strMemCountPrefix = modelParameter.MemCountPrefix;
        parameter.strMemRechargePrefix = modelParameter.MemRechargePrefix;
        parameter.strGoodsInPrefix = modelParameter.GoodsInPrefix;
        parameter.strGoodsAllotPrefix = modelParameter.GoodsAllotPrefix;
        parameter.strMemDrawMoneyPrefix = modelParameter.MemDrawMoneyPrefix;
        parameter.strMemDrawSmallChangePrefix = modelParameter.MemDrawSmallChangePrefix;
        parameter.strMemPointChangePrefix = modelParameter.MemPointChangePrefix;
        parameter.strGiftExchangePrefix = modelParameter.GiftExchangePrefix;
        parameter.strTimeExpensePrefix = modelParameter.TimeExpensePrefix;
        parameter.bolAutoPrint = modelParameter.AutoPrint;
        parameter.bolAccordPrint = modelParameter.AccordPrint;
        parameter.strPrintTitle = modelParameter.PrintTitle;
        parameter.strPrintFootNote = modelParameter.PrintFootNote;
        parameter.bolSms = modelParameter.Sms;
        parameter.bolMoneySms = modelParameter.MoneySms;
        parameter.bolIsSmsShopName = modelParameter.IsSmsShopName;
        parameter.strSmsShopName = modelParameter.SmsShopName;
        parameter.strNotificationSMS = modelParameter.SmsSeries;
        parameter.strNotificationSMSPwd = modelParameter.SmsSerialPwd;
        parameter.bolMarketingSMS = modelParameter.MarketingSMS;
        parameter.strMarketingSmsSeries = modelParameter.MarketingSmsSeries;
        parameter.strMarketingSmsSerialPwd = modelParameter.MarketingSmsSerialPwd;
        parameter.bolTel = modelParameter.Tel;
        parameter.bolTelNoMember = modelParameter.TelNoMember;
        parameter.bolStaff = modelParameter.IsStaff;
        parameter.bolStaffType = modelParameter.StaffType;
        parameter.chkPointLevel = modelParameter.PointLevel;
        parameter.bolMMS = modelParameter.MMS;
        parameter.strMMSSeries = modelParameter.MMSSeries;
        parameter.strMMSSerialPwd = modelParameter.MMSSerialPwd;
        parameter.bolIsPayCard = modelParameter.IsPayCard;
        parameter.bolIsPayCash = modelParameter.IsPayCash;
        parameter.bolIsPayBink = modelParameter.IsPayBink;
        parameter.bolIsPayCoupon = modelParameter.IsPayCoupon;
        parameter.EmailAdress = modelParameter.EmailAdress;
        parameter.EmailPwd = modelParameter.EmailPwd;
        parameter.EmailSMTP = modelParameter.EmailSMTP;
        parameter.intStockCount = modelParameter.StockCount;
        parameter.strUnitList = modelParameter.UnitList;
        parameter.strMoneyList = modelParameter.MoneyList;
        parameter.bolWeiXinSMSVcode = modelParameter.WeiXinSMSVcode;
        parameter.bolAutoSendSMSByMemRegister = modelParameter.IsAutoSendSMSByMemRegister;
        parameter.bolAutoSendMMSByMemRegister = modelParameter.IsAutoSendMMSByMemRegister;
        parameter.bolAutoSendSMSByMemRecharge = modelParameter.IsAutoSendSMSByMemRecharge;
        parameter.bolAutoSendSMSByMemWithdraw = modelParameter.IsAutoSendSMSByMemWithdraw;
        parameter.bolAutoSendSMSByMemGiftExchange = modelParameter.IsAutoSendSMSByMemGiftExchange;
        parameter.bolAutoSendSMSByMemPointChange = modelParameter.IsAutoSendSMSByMemPointChange;
        parameter.bolAutoSendSMSByCommodityConsumption = modelParameter.IsAutoSendSMSByCommodityConsumption;
        parameter.bolAutoSendSMSByFastConsumption = modelParameter.IsAutoSendSMSByFastConsumption;
        parameter.bolAutoSendSMSByMemRedTimes = modelParameter.IsAutoSendSMSByMemRedTimes;
        parameter.bolAutoSendSMSByTimingConsumption = modelParameter.IsAutoSendSMSByTimingConsumption;
        parameter.SellerAccount = modelParameter.SellerAccount;
        parameter.PartnerID = modelParameter.PartnerID;
        parameter.PartnerKey = modelParameter.PartnerKey;
        parameter.IsEditPwdNeedOldPwd = modelParameter.IsEditPwdNeedOldPwd;
        parameter.bolWeiXinType = modelParameter.WeiXinType;
        parameter.bolWeiXinVerified = modelParameter.WeiXinVerified;
        parameter.strWeiXinToken = modelParameter.WeiXinToken;
        parameter.strWeiXinShopName = modelParameter.WeiXinShopName;
        parameter.strWeiXinSalutatory = modelParameter.WeiXinSalutatory;
        parameter.strWeiXinAppID = modelParameter.WeiXinAppID;
        parameter.strWeiXinAppSecret = modelParameter.WeiXinAppSecret;
        parameter.intSignInPoint = modelParameter.SignInPoint;
        parameter.bolIsMemRegisterStaff = modelParameter.IsMemRegisterStaff;
        parameter.StorageTimingPrefix = modelParameter.StorageTimingPrefix;
        parameter.IsMustSlotCard = modelParameter.IsMustSlotCard;
        parameter.IsAutoSendSMSByStorageTiming = modelParameter.IsAutoSendSMSByStorageTiming;
        parameter.EnterpriseEmailPort = modelParameter.EnterpriseEmailPort;
        parameter.EnterpriseEmailDisplayName = modelParameter.EnterpriseEmailDisplayName;
        parameter.EnterpriseEmailEnableSSL = modelParameter.EnterpriseEmailEnableSSL;
        parameter.EnterpriseEmailUseDefaultCredentials = modelParameter.EnterpriseEmailUseDefaultCredentials;
        parameter.bolIsEmail = modelParameter.IsEmail;
        parameter.bolIsEmailNotice = modelParameter.IsEmailNotice;
        parameter.strMemCountExpensePrefix = modelParameter.MemCountExpensePrefix;
        parameter.strWeiXinEncodingAESKey = modelParameter.WeiXinEncodingAESKey;
        parameter.bolIsAutoSendSMSByMemPast = modelParameter.IsAutoSendSMSByMemPast;
        parameter.intAutoSendSMSByMemPastForDay = modelParameter.AutoSendSMSByMemPastForDay;
        parameter.bolIsAutoSendSMSByMemBirthday = modelParameter.IsAutoSendSMSByMemBirthday;
        parameter.intAutoSendSMSByMemBirthdayForDay = modelParameter.AutoSendSMSByMemBirthdayForDay;
        parameter.bolIsStartWeiXin = modelParameter.IsStartWeiXin;
        parameter.bolIsStartMoney = modelParameter.IsStartMoney;
        parameter.bolIsStartTimingProject = modelParameter.IsStartTimingProject;
        parameter.bolIsStartMemCount = modelParameter.IsStartMemCount;
        parameter.bolSenseiccard = modelParameter.Senseiccard;
        parameter.bolContacticcard = modelParameter.Contacticcard;
        parameter.strEmailUserName = modelParameter.EmailUserName;
        if (parameter.UsingUnion)
        {
            parameter.bolIsSendCard = modelParameter.IsSendCard;
            parameter.bolShopSmsManage = modelParameter.ShopSmsManage;
            parameter.bolShopPointManage = modelParameter.ShopPointManage;
            parameter.bolIsSettlement = modelParameter.ShopSettlement;
        }
        else
        {
            parameter.bolIsSendCard = false;
            parameter.bolShopSmsManage = false;
            parameter.bolShopPointManage = false;
            parameter.bolIsSettlement = false;
        }
        parameter.PointNumStr = modelParameter.PointNumStr;
        parameter.PrintPreview = modelParameter.PrintPreview;
        parameter.PrintPaperType = modelParameter.PrintPaperType;
        parameter.AutoBackupDB = modelParameter.AutoBackupDB;
        parameter.AutoBackupDay = modelParameter.AutoBackupDay;
        if (parameter.strDoMain != modelParameter.SystemDomain)
        {
            modelParameter.SystemDomain = parameter.strDoMain;
            bllParameter.Update(modelParameter);
        }
        parameter.IsDepositToWxRedPocket = modelParameter.IsDepositToWxRedPocket;
        parameter.DepositLimitMoney = modelParameter.DepositLimitMoney;
        parameter.DepositLimitTimes = modelParameter.DepositLimitTimes;
        return parameter;
    }

    public static string RemoveSpace(string Field)
    {
        string strField = Field;
        return strField.Replace("\n", "").Replace(" ", "");
    }

    public static void SaveSysLog(int userID, int actionID, string type, string detail, int shopID, DateTime createTime, string ipAdress)
    {
        Chain.Model.SysLog modelLog = new Chain.Model.SysLog();
        modelLog.LogUserID = userID;
        modelLog.LogActionID = actionID;
        modelLog.LogType = type;
        modelLog.LogDetail = detail;
        modelLog.LogShopID = shopID;
        modelLog.LogCreateTime = createTime;
        modelLog.LogIPAdress = ipAdress;
        new Chain.BLL.SysLog().Add(modelLog);
    }

    public static bool SetMemSex(int intMemSex)
    {
        return (intMemSex == 0);
    }

    public static void SetPageNavigation(int MenuID, ref Literal lblTitle)
    {
        StringBuilder strHtml = new StringBuilder();
        strHtml.Append("<a href='/StartPage.aspx'>主页</a>&nbsp;&nbsp;>");
        Chain.Model.SysModule mdSysModule = new Chain.BLL.SysModule().GetModel(MenuID);
        if (mdSysModule.ModuleParentID > 0)
        {
            strHtml.Append(BindFatherHtml(mdSysModule.ModuleParentID, ""));
        }
        strHtml.Append(string.Format("&nbsp;&nbsp;{0}", mdSysModule.ModuleCaption));
        lblTitle.Text = strHtml.ToString();
    }

    public static void SetShopPoint(int UserID, int ShopID, int Point, string Remark, int Type)
    {
        if ((Point != 0) && (ShopID > 1))
        {
            Chain.BLL.SysShop bllSysShop = new Chain.BLL.SysShop();
            Chain.Model.SysShop mdSysShop = new Chain.Model.SysShop();
            mdSysShop = bllSysShop.GetModel(ShopID);
            if (curParameter.isPointSame && ((mdSysShop.PointType != 1) || (Point <= mdSysShop.PointCount)))
            {
                mdSysShop.PointCount -= Point;
                bllSysShop.Update(mdSysShop);
                Chain.BLL.SysShopPointLog bllSysShopPointLog = new Chain.BLL.SysShopPointLog();
                Chain.Model.SysShopPointLog mdSysShopPointLog = new Chain.Model.SysShopPointLog();
                mdSysShopPointLog.Count = -1 * Point;
                mdSysShopPointLog.CreateTime = DateTime.Now;
                mdSysShopPointLog.OutShopID = ShopID;
                mdSysShopPointLog.ShopID = ShopID;
                mdSysShopPointLog.ShopPointAccount = "JF" + DateTime.Now.ToString("yyMMddHHmmssffff");
                mdSysShopPointLog.ShopPointType = Type;
                mdSysShopPointLog.UserID = UserID;
                mdSysShopPointLog.Remark = Remark;
                bllSysShopPointLog.Add(mdSysShopPointLog);
            }
        }
    }

    public static void SetShopSms(int UserID, int ShopID, int MemMobileCount, int Type)
    {
        if (ShopID > 1)
        {
            Chain.BLL.SysShop bllSysShop = new Chain.BLL.SysShop();
            Chain.Model.SysShop mdSysShop = bllSysShop.GetModel(ShopID);
            if (curParameter.IsSmsSame && ((mdSysShop.SmsCount >= MemMobileCount) || (mdSysShop.SmsType != 1)))
            {
                mdSysShop.SmsCount -= MemMobileCount;
                bllSysShop.Update(mdSysShop);
                Chain.BLL.SysShopCmsLog bllSysShopCmsLog = new Chain.BLL.SysShopCmsLog();
                Chain.Model.SysShopCmsLog mdSysShopCmsLog = new Chain.Model.SysShopCmsLog();
                mdSysShopCmsLog.Count = -1 * MemMobileCount;
                mdSysShopCmsLog.CreateTime = DateTime.Now;
                mdSysShopCmsLog.OutShopID = ShopID;
                mdSysShopCmsLog.ShopCmsAccount = "DX" + DateTime.Now.ToString("yyMMddHHmmssffff");
                mdSysShopCmsLog.ShopCmsType = Type;
                mdSysShopCmsLog.ShopID = ShopID;
                mdSysShopCmsLog.UserID = UserID;
                mdSysShopCmsLog.Remark = mdSysShop.ShopName + "店铺使用短信";
                bllSysShopCmsLog.Add(mdSysShopCmsLog);
            }
        }
    }

    public static string SexToName(bool sex)
    {
        if (sex)
        {
            return "男";
        }
        return "女";
    }

    public static string ShopIDToName(int shopID)
    {
        Chain.Model.SysShop modelShop = new Chain.BLL.SysShop().GetModel(shopID);
        if (modelShop != null)
        {
            return modelShop.ShopName;
        }
        return "";
    }

    public static string StateToName(int state)
    {
        if (state == 0)
        {
            return "正常";
        }
        if (state == 1)
        {
            return "锁定";
        }
        if (state == 2)
        {
            return "挂失";
        }
        return "";
    }

    public static void SubTractCont(int mytime, int memid, int projectid)
    {
        int owntime = 0;
        Chain.BLL.MemStorageTiming bllMemStorageTiming = new Chain.BLL.MemStorageTiming();
        DataTable dtMemStorageTiming = bllMemStorageTiming.GetList(string.Format("StorageResidueTime > 0 AND StorageTimingMemID = {0} AND StorageTimingProjectID = {1}", memid, projectid)).Tables[0];
        foreach (DataRow drMemStorageTiming in dtMemStorageTiming.Rows)
        {
            owntime = Convert.ToInt32(drMemStorageTiming["StorageResidueTime"]);
            if (owntime >= mytime)
            {
                bllMemStorageTiming.UpdateStorageResidueTime(Convert.ToInt32(drMemStorageTiming["StorageTimingID"]), owntime - mytime);
                mytime = 0;
            }
            else
            {
                bllMemStorageTiming.UpdateStorageResidueTime(Convert.ToInt32(drMemStorageTiming["StorageTimingID"]), 0);
                mytime -= owntime;
            }
            if (mytime == 0)
            {
                break;
            }
        }
    }

    public static string SysAreaName(int areaID)
    {
        return new Chain.BLL.SysArea().GetModel(areaID).Name;
    }

    public static void SysEdition(int type)
    {
        Chain.BLL.SysModule bllModule = new Chain.BLL.SysModule();
        int intType = 0;
        if (type == 1)
        {
            intType = 1;
        }
        else
        {
            intType = 0;
        }
        bllModule.UpdateIsDataInit(intType);
    }

    public static void SysEnableGoods()
    {
        new Chain.BLL.SysModule().SetEnableGoods(curParameter.EnableGoods);
    }

    public static void SysUpdateMemIsPast()
    {
        new Chain.BLL.Mem().SysUpdateMemIsPast();
    }

    public static string TimeEndDay(string timeEnd)
    {
        if (timeEnd != "")
        {
            return DateTime.Parse(timeEnd).AddDays(1.0).ToShortDateString();
        }
        return timeEnd;
    }

    public static void TimeExpenseEnd(string strOrderAccount, int uid, DateTime date, string strOrderRemark)
    {
        Chain.BLL.OrderTime bllOrderTime = new Chain.BLL.OrderTime();
        Chain.Model.OrderTime modelOrderTime = new Chain.Model.OrderTime();
        DataTable dtTiemExpense = bllOrderTime.GetList(string.Format("OrderTimeCode = '{0}'", strOrderAccount)).Tables[0];
        if (dtTiemExpense.Rows.Count > 0)
        {
            modelOrderTime = bllOrderTime.GetModel(int.Parse(dtTiemExpense.Rows[0]["OrderTimeID"].ToString()));
            modelOrderTime.OrderState = true;
            modelOrderTime.OrderOutTime = date;
            modelOrderTime.OrderEndUserID = uid;
            modelOrderTime.OrderRemark = strOrderRemark;
            bllOrderTime.Update(modelOrderTime);
        }
    }

    public static void UpdateGroupAuthority(int GroupID)
    {
        _grouAuthority.Remove(GroupID);
    }

    public static string UpdateMemLevel(Chain.Model.Mem memInfo)
    {
        string str = "";
        if (curParameter.bolAutoLevel)
        {
            Chain.BLL.Mem bllMem = new Chain.BLL.Mem();
            List<Chain.Model.MemLevel> listLevel = new Chain.BLL.MemLevel().GetModelList("  SysShopMemLevel.ShopID=" + memInfo.MemShopID);
            Chain.Model.MemLevel level = listLevel.Find(delegate (Chain.Model.MemLevel p) {
                return p.LevelID == memInfo.MemLevelID;
            });
            if (level.LevellLock)
            {
                return str;
            }
            listLevel.Sort(delegate (Chain.Model.MemLevel p1, Chain.Model.MemLevel p2) {
                return Comparer<int>.Default.Compare(p1.LevelPoint, p2.LevelPoint);
            });
            if (memInfo.MemPoint <= 0)
            {
                return str;
            }
            Chain.Model.MemLevel computelevel = listLevel.FindLast(delegate (Chain.Model.MemLevel p) {
                return p.LevelPoint <= memInfo.MemPoint;
            });
            int oldLevel = listLevel.FindIndex(0, delegate (Chain.Model.MemLevel p) {
                return p.LevelID == memInfo.MemLevelID;
            });
            int newLevel = listLevel.FindIndex(0, delegate (Chain.Model.MemLevel p) {
                return p.LevelID == computelevel.LevelID;
            });
            if (newLevel == oldLevel)
            {
                return str;
            }
            if (newLevel > oldLevel)
            {
                bllMem.UpdateLevel(memInfo.MemID, computelevel.LevelID);
                str = "  该会员已经从【" + level.LevelName + "】升级为【" + computelevel.LevelName + "】";
                SaveSysLog(memInfo.MemUserID, 4, "会员自动升级", "会员升级,会员卡号：[" + memInfo.MemCard + "],姓名：[" + memInfo.MemName + "]", memInfo.MemUserID, DateTime.Now, ipAdress);
            }
            else if (curParameter.bolDegradeLevel)
            {
                bllMem.UpdateLevel(memInfo.MemID, computelevel.LevelID);
                str = "  该会员已经从【" + level.LevelName + "】降级为【" + computelevel.LevelName + "】";
                SaveSysLog(memInfo.MemUserID, 4, "会员自动降级", "会员降级,会员卡号：[" + memInfo.MemCard + "],姓名：[" + memInfo.MemName + "]", memInfo.MemUserID, DateTime.Now, ipAdress);
            }
            if ((memInfo.MemMobile != "") && curParameter.bolMoneySms)
            {
                SmsTemplateParameter smsTemplateParameter = new SmsTemplateParameter();
                smsTemplateParameter.strCardID = memInfo.MemCard;
                smsTemplateParameter.strName = memInfo.MemName;
                smsTemplateParameter.dclTempMoney = 0M;
                smsTemplateParameter.dclMoney = memInfo.MemMoney;
                smsTemplateParameter.intTempPoint = 0;
                smsTemplateParameter.intPoint = memInfo.MemPoint;
                smsTemplateParameter.OldLevelID = level.LevelID;
                smsTemplateParameter.NewLevelID = computelevel.LevelID;
                string strSendContent = SMSInfo.GetSendContent(6, smsTemplateParameter, memInfo.MemShopID);
                SMSInfo.Send_GXSMS(false, memInfo.MemMobile, strSendContent, "");
                Chain.Model.SmsLog modelSms = new Chain.Model.SmsLog();
                modelSms.SmsMemID = memInfo.MemID;
                modelSms.SmsMobile = memInfo.MemMobile;
                modelSms.SmsContent = strSendContent;
                modelSms.SmsTime = DateTime.Now;
                modelSms.SmsShopID = memInfo.MemShopID;
                modelSms.SmsUserID = memInfo.MemUserID;
                modelSms.SmsAmount = GetSmsAmount(strSendContent);
                modelSms.SmsAllAmount = modelSms.SmsAmount;
                new Chain.BLL.SmsLog().Add(modelSms);
                SaveSysLog(memInfo.MemUserID, 4, "自动发送会员等级短信", "会员等级变动,会员卡号：[" + memInfo.MemCard + "],姓名：[" + memInfo.MemName + "]", memInfo.MemUserID, DateTime.Now, ipAdress);
            }
        }
        return str;
    }

    public static string UserIDTOName(int userID)
    {
        Chain.Model.SysUser modelUser = new Chain.BLL.SysUser().GetModel(userID);
        if (modelUser != null)
        {
            return modelUser.UserName;
        }
        return "";
    }

    public static CurrentParameter curParameter
    {
        get
        {
            if (_parameter == null)
            {
                lock (SynObject)
                {
                    if (_parameter == null)
                    {
                        _parameter = new PubFunction().LoadSysParameter();
                    }
                }
            }
            return _parameter;
        }
        set
        {
            _parameter = null;
        }
    }

    public static string ipAdress
    {
        get
        {
            if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
            {
                return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];
            }
            return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }
    }

    public static int ProductDecimalNum
    {
        get
        {
            return curParameter.ProductDecimalNum;
        }
    }

    private enum ActionID
    {
        MemAdd = 1,
        MemDelete = 3,
        MemEdit = 2
    }
}

